import * as commonService from 'services/commonService';
import { remoteLinkAddress } from 'utils/ip';
import { getSession } from 'utils/utils';
import { COUNT_DOWN } from 'utils/Enum'
export default {
  namespace: 'signTheSuccessModel',
  state: {
    pdfList: [],
    count: COUNT_DOWN.RESULT_TIME,
  },
  effects: {
    *getPDFList({ payload, callback }, { call, put }) {
      const response = yield call(commonService.getPDFList, payload);
      if (response.code.substring(response.code.length - 4) == '0000') {
        const { contents } = response;
        const pdfList = contents.map(content => ({
          id: content.fileWsid,
          name: content.fileName,
          pdfSrc: `${remoteLinkAddress()}file${
            content.fileHref.href
            }?X-Requested-Session=${getSession()}`,
        }));
        yield put({
          type: 'save',
          payload: {
            pdfList,
          },
        });
        callback('success')
      } else {
        callback('error', response.message)
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    countDown(state, { payload }) {
      return {
        ...state,
        count: payload
      }
    },
  },
  subscriptions: {},
};
